<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>黑名单</title>
    <style>
        .import {
            margin-bottom: 10px;
        }

        .line {
            display: inline-block;
            vertical-align: top;
        }
    </style>
</head>
<body>
<div>
{{--    <div class="line">--}}
{{--        <button style="background-color: #008d4c;" type="button" class="layui-btn import layui-btn-sm">--}}
{{--            <i class="layui-icon">&#xe67c;</i>上传黑名单--}}
{{--        </button>--}}
{{--    </div>--}}
{{--    <div class="line">--}}
{{--        <button type="button" class="layui-btn layui-bg-red patch_btn layui-btn-sm">--}}
{{--            批量删除--}}
{{--        </button>--}}
{{--    </div>--}}

</div>
<table id="table" class="display">
    <thead>
    <tr>
{{--        <th>删除</th>--}}
        <th>ID</th>
        <th>姓名</th>
        <th>电话</th>
        <th>身份证</th>
        <th>来源</th>
        <th>创建时间</th>
        <th>操作</th>
    </tr>
    </thead>
    <tbody>
    </tbody>
    <tfoot></tfoot>
</table>
</body>
<script>
    //jQuery的载入事件
    $(function () {
        $('#table').dataTable().fnDestroy();
        //初始化datatables
        var _dataTablesInstance = $('#table').dataTable({
            //开启服务端模式
            serverSide: true,
            //指定服务端数据获取地址（ajax地址）
            ajax: "/admin/common/black/list",
            //将数据表的列与表格的列进行绑定
            columns: [
                // {"data": "a", "defaultContent": "复选框"},
                {"data": "id"},
                {"data": "name"},
                {"data": "mobile"},
                {"data": "id_no"},
                {"data": "class_name"},
                {"data": "created_time"},
                {"data": "b", "defaultContent": "我是状态"},
            ],
            //createdRow回调去完善每一行
            createdRow: function (row, data, dataIndex) {
                //给每一行添加text-c的class属性值，让其居中
                $(row).addClass('text-c');
                //需要更改第一个单元格的内容为复选框
                // $(row).find('td:eq(0)').html("<input type='checkbox' class='patch_del' data-mobile='"+ data.mobile +"' value='" + data.id + "'/>");
                // $(row).find('td:eq(3)').html("<span type='checkbox' class='mobile'>"+data.mobile+"</span>");

                //判断帐号状态，根据对应值显示对应的效果
                $(row).find('td:eq(6)').html("<button onclick='del("+data.id+","+data.mobile+")' type='button' class='layui-btn layui-btn-xs'>删除</button>");
            },
            //部分字段不参与排序
            // aoColumnDefs: [ { "bSortable": false, "aTargets": [ 0,2,3,4,5,6 ] }] ,
            //更改默认排序
            // aaSorting: [[ 1, "desc" ]],
            // bSort: false,
            language: {
                "sProcessing": "处理中...",
                "sLengthMenu": "显示 _MENU_ 项结果",
                "sZeroRecords": "没有匹配结果",
                "sInfo": "显示第 _START_ 至 _END_ 项结果，共 _TOTAL_ 项",
                "sInfoEmpty": "显示第 0 至 0 项结果，共 0 项",
                "sInfoFiltered": "(由 _MAX_ 项结果过滤)",
                "sInfoPostFix": "",
                "sSearch": "搜索:",
                "sUrl": "",
                "sEmptyTable": "暂无数据",
                "sLoadingRecords": "载入中...",
                "sInfoThousands": ",",
                "oPaginate": {
                    "sFirst": "首页",
                    "sPrevious": "上页",
                    "sNext": "下页",
                    "sLast": "末页"
                },
                "oAria": {
                    "sSortAscending": ": 以升序排列此列",
                    "sSortDescending": ": 以降序排列此列"
                },
                "bPaginate": true, //翻页功能
            }
        });
    });
</script>
<script>

    function del(oid, mobile) {
        layer.confirm('确定要删除吗?', {icon: 3, title: '提示'}, function (index) {
            $.ajax({
                url: '/admin/common/black/delblack',
                type: 'post',
                data: {
                    'oid': oid,
                    'mobile': mobile
                },
                success: function (res) {
                    console.log();
                    if (res.code == 0) {
                        layer.msg(res.text)
                        $(".container-refresh").click();
                        layer.close(index);
                    } else {
                        layer.msg(res.text);
                    }
                }
            })
        });
    }

    $(function () {

        $('.patch_btn').click(function () {
            var vals = $('.patch_del:checked').val();
            if (typeof (vals) == 'undefined') {
                layer.msg('没有选择数据');
                return;
            }
            var orderid = [];
            var mobiles = [];
            $('.patch_del:checked').each(function (index, ele) {
                orderid.push($(ele).val());
                mobiles.push($(ele).attr('data-mobile'));
            });
            if (count(orderid) <= 0) {
                layer.msg('没有选择数据');
                return;
            }
            var orderids = orderid.join(',');
            var mobiles = mobiles.join(',');
            layer.confirm('确定要删除吗?', {icon: 3, title: '提示'}, function (index) {
                $.ajax({
                    url: '/admin/common/black/delblack',
                    type: 'post',
                    data: {
                        'oid': orderids,
                        'mobile': mobiles
                    },
                    success: function (res) {
                        if (res.code == 0) {
                            layer.msg(res.text)
                            $(".container-refresh").click();
                            layer.close(index);
                        } else {
                            layer.msg(res.text);
                        }
                    }
                })
            });
        })

        $('.import').click(function () {
            layer.open({
                title: '上传黑名单',
                type: 2,
                content: '/admin/common/upload/black/excel',
                area: ['482px', '300px'],
            });
        });
    })
</script>
<script>
    function count(o) {//获取数组长度
        var t = typeof o;
        if (t == 'string') {
            return o.length;
        } else if (t == 'object') {
            var n = 0;
            for (var i in o) {
                n++;
            }
            return n;
        }
        return false;
    }
</script>
</html>